microbit = codesters.Microbit()
microbit.show_string("hello")
stage.set_background("soccerfield")
sprite = codesters.Sprite("athlete2")
sprite.move_down(150)
def button_a():
sprite.move_left(50)
microbit.event_button_a(button_a)
def button_b():
sprite.move_right(50)
microbit.event_button_b(button_b)
ball = codesters.Sprite("soccerball")
ball.set_x_speed(5)
ball.set_y_speed(5)
def collision(sprite, hit_sprite):
sprite.go_to(0, 0)
hit_sprite.hide()
# add any other actions...
sprite.event_collision(collision)
t = codesters.Teacher()
try:
go_to = t.find_function('go_to')
tval1 = go_to[0][1]
except:
tval1 = "DNE"
try:
hide = t.find_function('hide')
tval2 = hide[0][1]
except:
tval2 = "DNE"
try:
set_y_speeds = t.find_function("set_y_speed")
tval3 = set_y_speeds[1][1]
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == "DNE", "Great job!")
t1.add_failure(tval1 != "DNE", "Did you delete the line with sprite.go_to(0, 0)?")
t2 = TestObjective()
t2.add_success(tval2 == "DNE", "Great job!")
t2.add_failure(tval2 != "DNE", "Did you delete the line with hit_sprite.hide()?")
t3 = TestObjective()
t3.add_success(tval3 == "sprite.set_y_speed(5)", "Great job!")
t3.add_failure(tval3 == "DNE", "Did you add in the Set y Speed command?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)